<?php


header('Content-Type: image/jpeg');

$user=$_GET['user'];
$url=$_GET['img'];


preg_match("/([0-9a-zA-Z\.]{1,9})$/",$_GET['img'],$matched);

$full_name="/home/xfliu/image_backup/${user}_".$matched[1];

if(file_exists($full_name) )
{
	$url=$full_name;
	$fh=fopen($url,"r");
	while(!feof($fh)) {
 	echo fgets($fh, 4096);
	}
	fclose($fh);
}
else
{
$fh=fopen($url,"r");
$output=NULL;
while(!feof($fh)) {
 		$line=fgets($fh, 4096);
		$output.=$line;
		echo $line;
}
fclose($fh);

$fh2=fopen($full_name,"w");
fwrite($fh2,$output);
fclose($fh2);

}

?>
